package top.jnaw.jee.platform.model;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.kit.StrKit;
import top.jnaw.jee.utils.ModelResult;

/**
 * Copyright (C) 2018 版权所有。 <p> 文件名： 文件功能描述：
 *
 * @author lc  2018/7/20 14:47 创建内容： <p> <p> 修改标识： 修改原因：
 */
public class DepartmentCallBack implements CallBack.Callback {

  private CallBack mCallback;

  public DepartmentCallBack() {
    mCallback = new CallBack(this);
  }

  @Override
  public boolean after(JSONArray row) {
    boolean r = false;
    if (null != row) {
      String mobile = "";
      String name = "";
      String type = "";
      String admin = "";
      boolean is_admin;
      for (Object o : row) {
        if (JSONObject.parseObject(o.toString()).getString("cell")
            .contains("A")) {
          name = JSONObject.parseObject(o.toString()).getString("value");
        }
        if (JSONObject.parseObject(o.toString()).getString("cell")
            .contains("B")) {
          mobile = JSONObject.parseObject(o.toString()).getString("value");
        }
        if (JSONObject.parseObject(o.toString()).getString("cell")
            .contains("C")) {
          type = JSONObject.parseObject(o.toString()).getString("value");
        }
        if (JSONObject.parseObject(o.toString()).getString("cell")
            .contains("D")) {
          admin = JSONObject.parseObject(o.toString()).getString("value");
        }
      }
      type = "部门".equals(type) ? "1" : "2";
      is_admin = "是".equals(admin);
      if (StrKit.notBlank(name, mobile, type)) {
        ModelResult result = Department.add(name, Integer.parseInt(type));
        if (result.fine()) {
          Department department = (Department) result.getObject();
          JSONArray array = new JSONArray();
          array.add(department.getId());
          //r = Users.add(mobile, is_admin, array).fine();
        }
      }

    }
    return r;
  }

  public ModelResult foo(String url, int i) {

    return mCallback.foo(url, i);
  }
}
